﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Intergr8.GoogleVisualization.Interfaces;
//using Intergr8.GoogleVisualization;
//using Intergr8.GoogleVisualization.DataFactory;
//using Intergr8.Data.DataManagement;

/// <summary>
/// Summary description for DataServerBase
/// </summary>
public class DataServerBase :  System.Web.UI.Page 
{
    private string _dataSource = "";

    /// <summary>
    /// 
    /// </summary>
    public DataServerBase()
    {
        _dataSource = "";
    }


    /// <summary>
    /// Constrct for a particular DataSource
    /// </summary>
    /// <param name="dataSource"></param>
    public DataServerBase(string dataSource)
    {
        _dataSource = dataSource;
    }


    /// <summary>
    /// Set/Get the current DataSource
    /// </summary>
    protected string DataSource
    {
        get { return _dataSource; }
        set { _dataSource = value; }
    }


    protected string GenerateDataResponse(HttpRequest httpRequest)
    {
       
        //Pick up the URL request parameters.
        IRequestHandler reqHandler = Intergr8.GoogleVisualization.DataFactory.VisualizationDataRequestFactory.CaptureRequest(httpRequest);

       

        //System.Data.DataTable data = null;
        //IResponseData responsedata = null;
        //responseMessage = null;

         IResponseMessage responseMessage = Intergr8.GoogleVisualization.DataFactory.VisualizationDataRequestFactory.CreateResponse(reqHandler, _dataSource);

        //try
        //{
        //    DataSourceManager dsm = new DataSourceManager();
        //    data = dsm.Fetch(_dataSource);

        //    // Wrap up the data to return
        //    responsedata = ResponseData.GenerateResponseData(data);

        //    // Generate a Response
        //    responseMessage = ResponseMessage.CreateResponse(reqHandler, responsedata);
        //}
        //catch (Exception ex)
        //{
        //    //responsedata = some blank default data

        //    // Generate a Response indicating that a data error occurred
        //    responseMessage = ResponseMessage.CreateResponse(reqHandler, ex );

        //}


        // Clear all data from the buffer stream
        Response.Clear();

        // Correctly set the content and MIME type
        Response.ContentType = "text/plain";
        Response.Charset = "UTF-8";

        // Write the Response
        //httpResponse.Write(responseMessage.Output());

        return responseMessage.Output();
    }
}
